home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FrameFormatter.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _FrameFormatter_
- #define _FrameFormatter_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _TextensionCommon_
- #include "TextensionCommon.h"
- #endif
-
-
- #ifndef _Array_
- #include "Array.h"
- #endif
-
-
- #ifndef _ObjectsRanges_
- #include "ObjectsRanges.h" //for CRanges
- #endif
-
- //***************************************************************************************************
-
- struct TLineHiteGroup { //lines having the same lineHiteInfo
- long groupCountLines; //count of lines in this group
- short lineHite;
- short lineAscent;
-
- #ifdef txtnScal
- short scaledHite;
- short scaledAscent;
- #endif
- };
- typedef TLineHiteGroup* TLineHiteGroupPtr;
-
- //*************************************************************************************************
-
-
- #ifdef txtnMultiFrames
- typedef short TFrameEditFlags;
-
- //constant for T1FrameEditInfo flags
-
- const TFrameEditFlags kInvalidWholeFrame = 1; //need redraw the whole frame
-
- const TFrameEditFlags kInvalidFrameFootNotes = 1 << 1;
-
- //• constants 1 << 2 through 1 << 7 are reserved for future "invalid content parts" bits
-
- const TFrameEditFlags kInvalidMask = 0x00FF;
-
- const TFrameEditFlags kInvalidContentMask = 0x00FE; //used internally
-
- const TFrameEditFlags kInvalidFrameText = 1 << 8; //need redraw the text inside the frame
-
-
- struct T1FrameEditInfo {
- long frameNo;
- TFrameEditFlags flags;
- long invalMessage;
- long hiteModif; //scaled
- short overflowIn; //scaled
- short overflowOut; //scaled
- };
-
- const short kMaxEditFrames = 50;
-
-
- class CFrameEditInfo : private SingleObject {
- public :
- CFrameEditInfo() {fCount = 0;}
-
- inline void BeginEdit() {
- fCount = 0;
- fIterateIndex = 0;
- }
-
- inline void EndEdit() {fCount = 0;}
-
- inline GetCount() {return fCount;}
-
- T1FrameEditInfo* CatchFrame(long frameNo);
-
- Boolean GetEditInfoPtr(long frameNo, T1FrameEditInfo** editInfo
- , TFrameEditFlags mask = kInvalidFrameText+kInvalidWholeFrame) const;
-
- T1FrameEditInfo* GetNext();
-
- void SetEditFlag(TFrameEditFlags flagVal, long startFrame = 0, short count = kMaxInt);
-
- private:
- short fCount;
- T1FrameEditInfo fEditInfo[kMaxEditFrames];
-
- long fFirstFrame;
- long fLastFrame;
-
- short fIterateIndex;
- };
-
- extern CFrameEditInfo gFrameEditInfo;
- //*************************************************************************************************
-
- //const for CFormatReflowLines SetReflowType and GetReflowType
- const char kNoReflow = 0;
- const char kOverflow = 1;
- const char kUnderflow = 2;
-
- class CFormatReflowLines : private SingleObject { //lines reflowing between frames and need horiz formatting
- public:
- CFormatReflowLines() {this->Reset();}
-
- void Reset();
-
- void SetFirst(long lineNo);
- void SetLast(long lineNo);
-
- Boolean GetFirst(long* lineNo) const;
- Boolean GetLast(long* lineNo) const;
-
- inline void SetReflowFlag(Boolean flag) {fAllowReflow = flag;}
- inline Boolean GetReflowFlag() const {return fAllowReflow;}
-
- inline void SetReflowType(char theType) {fReflowType = theType;}
- inline char GetReflowType() const {return fReflowType;}
-
- private:
- long fFirstLine;
- long fLastLine;
- Boolean fAllowReflow;
- char fReflowType; //kOverflow or kUnderflow
- };
- //*************************************************************************************************
- #endif
-
-
-
- class CLinesHites : public CArray {
- public:
- CLinesHites();
-
- void ILinesHites();
-
- virtual void FreeData();
-
- #ifdef txtnScal
- void GetLineHiteInfo(long lineNo, TLineHiteInfo* lineHiteInfo, Boolean scaled=true) const;
- #else
- void GetLineHiteInfo(long lineNo, TLineHiteInfo* lineHiteInfo) const;
- #endif
-
- #ifdef txtnMultiFrames
- virtual OSErr InsertLine(const TLineHiteInfo* lineHiteInfo, CFormatReflowLines* formatReflowLines,
- long lineNo = -1);
- virtual OSErr SetLineHiteInfo(const TLineHiteInfo* lineHiteInfo, long lineNo
- , CFormatReflowLines* formatReflowLines);
- virtual void RemoveLines(long countLines, long lineNo, CFormatReflowLines* formatReflowLines);
-
- #else
- virtual OSErr InsertLine(const TLineHiteInfo* lineHiteInfo, long lineNo = -1);
- virtual OSErr SetLineHiteInfo(const TLineHiteInfo* lineHiteInfo, long lineNo);
- virtual void RemoveLines(long countLines, long lineNo);
- #endif
-
- #ifdef txtnScal
- long Pixel2Line(long* vPix, Boolean scaled, long lineNo = 0
- , TLineHiteGroupPtr* hiteGroupPtr = nil, long* groupLineIndex = nil) const;
-
- long Hite2CountLines(const TLineHiteGroupPtr groupPtr, long groupLineNo, Boolean scaled, long* hite) const;
-
- long GetLinesHite(long firstLine, long lastLine, Boolean scaled=true) const;
-
- long GetTotalLinesHite(Boolean scaled = true) const;
-
- virtual void SetVScale(short numer, short denom);
-
- #else
- long Pixel2Line(long* vPix, long lineNo = 0
- , TLineHiteGroupPtr* hiteGroupPtr = nil, long* groupLineIndex = nil) const;
-
- long Hite2CountLines(const TLineHiteGroupPtr groupPtr, long groupLineNo, long* hite) const;
-
- long GetLinesHite(long firstLine, long lastLine) const;
-
- inline long GetTotalLinesHite() const {return fTotalHite;}
- #endif
-
-
- inline long CountLines() const {return fLastLineIndex+1;}
-
- protected:
- #ifdef txtnScal
- short fNumer;
- short fDenom;
- #endif
-
-
- private:
- long fTotalHite;
- /*to optimize the call of GetLinesHite if required all text hite, fTotalHite is kept scaled
- according to the sclae factor.*/
-
- long fLastLineIndex;
-
- TLineHiteGroupPtr Line2HiteGroup(long* lineNo, long* groupNo =nil) const;
- TLineHiteGroupPtr Pixel2HiteGroup(long* vPix, long* groupLineNo) const;
-
- Boolean EqualGroup(long groupIndex, const TLineHiteGroupPtr groupPtr) const;
- Boolean EqualGroup(long group1Index, long group2Index) const;
-
- Boolean Concat(long group1Index, long group2Index, const TLineHiteGroupPtr groupPtr = nil);
-
- #ifdef txtnScal
- void CalcScaledHiteInfo(TLineHiteGroup* groupPtr) const;
- #endif
- };
- //*************************************************************************************************
-
- class CFrameFormatter : public CLinesHites {
- public:
- CFrameFormatter();
-
- inline void IFrameFormatter() {this->ILinesHites();}
-
- //•override
-
- //•own members
-
- //following 2 members : some descendents may want to keep some char offsets (footNotes, frame breaks..)
- inline void SetLineEnds(const CRanges* lineEnds) {fLineEnds = lineEnds;}
- virtual void ReplaceCharRange(long offset, long oldLen, long newLen, Boolean newRuns = true);
- /*"newRuns" false ==> the range "offset..offset+oldLen" will be replace by the same run at
- "offset" (not used if newLen is 0)
- */
-
- virtual void SetFrameHite(long frameNo, short newHite) = 0; //newHite is non scaled
- virtual short GetFrameHite(long frameNo) const = 0; //returns a non scaled value
-
- #ifdef txtnScal
- virtual long GetFrameTextHite(long frameNo, Boolean scaled = true) const = 0;
- #else
- virtual long GetFrameTextHite(long frameNo) const = 0;
- #endif
-
- #ifdef txtnMultiFrames
- Boolean TestFrameOverflow(long lineNo, short newHite);
- //returns true if an overflow will occur if the line hite of "lineNo" is modified to "newHite"
- virtual OSErr ForceOverflow(long lineNo) = 0;
- #endif
-
- virtual OSErr Format();
-
- virtual long GetCountFrames() const = 0;
-
- virtual Boolean GetFrameLineRange(long frameNo, TOffsetPair* frameLines) const = 0;
- //returns false if no lines in the frame
-
- virtual long Line2Frame(TOffset offset) const = 0;
-
- #ifdef txtnMultiFrames
- Boolean GetFrameCharRange(long frameNo, TOffsetPair* frameChars) const;
-
- long Char2Frame(TOffset charOffset) const;
-
- //editing members
- virtual void BeginEdit();
- virtual void CatchFrame(long frameNo);
- virtual T1FrameEditInfo* GetNextFrameEditInfo();
- virtual void EndEdit();
- #endif
-
- protected:
- const CRanges* fLineEnds;
-
- private:
- };
- //*************************************************************************************************
-
- class CMonoFrameFormatter : public CFrameFormatter {
- public:
- CMonoFrameFormatter();
-
- inline void IMonoFrameFormatter() {this->IFrameFormatter();}
-
- //•override
-
- virtual void SetFrameHite(long frameNo, short newHite);
- virtual short GetFrameHite(long frameNo) const;
-
-
- #ifdef txtnScal
- virtual long GetFrameTextHite(long frameNo, Boolean scaled = true) const;
- #else
- virtual long GetFrameTextHite(long frameNo) const;
- #endif
-
- #ifdef txtnMultiFrames
- virtual OSErr ForceOverflow(long lineNo);
- #endif
-
- virtual long GetCountFrames() const;
-
- virtual Boolean GetFrameLineRange(long /*frameNo*/, TOffsetPair* frameLines) const;
-
- virtual long Line2Frame(TOffset offset) const ;
-
- #ifdef txtnMultiFrames
- virtual void CatchFrame(long frameNo);
- virtual T1FrameEditInfo* GetNextFrameEditInfo();
- #endif
- };
- //*************************************************************************************************
-
- #endif
-